/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2025-06-22
 * Time: 11:35
 */
//力扣162题：寻找峰值 二分算法
class Solution {
    //二分右端点
    public int findPeakElement(int[] nums) {
        int left = 0;
        int right = nums.length - 1;

        while (left < right) {
            int mid = left + (right - left + 1) / 2;

            if (nums[mid] > nums[mid - 1]) {
                left = mid;
            }else {
                right = mid - 1;
            }
        }

        return left;
    }


    //二分左端点
    public int findPeakElement2(int[] nums) {
        int left = 0;
        int right = nums.length - 1;

        while (left < right) {
            int mid = left + (right - left) / 2;

            if (nums[mid] < nums[mid + 1]) {
                left = mid + 1;
            }else {
                right = mid;
            }
        }

        return left;
    }
}
